<!--Code for adding an announcement to the database-->

<?php

session_start();

if (isset($_POST['submit'])) {
    $title = $_POST['annTitle'];
    $desc = $_POST['annDesc'];
    $date = $_POST['annDate'];

    include 'DBLibrary/config.php';
    include 'DBLibrary/openDB.php';

    mysql_select_db("rotaract");

    define('FileFolder', 'announcementImages/');

    if (isset($_POST['submit'])) {
        $dafile = $_FILES['imageUpload']['name'];
        $target = FileFolder . $dafile;

        move_uploaded_file($_FILES['imageUpload']['tmp_name'], $target);
    }

    
    $queryExisting = mysql_query("select * from `rotaract`.`announcement` where title='$title'");
    $resultExisting = mysql_fetch_array($queryExisting);

    if (empty($resultExisting)) {
        $confirm = mysql_query("INSERT INTO `rotaract`.`announcement` (`title`, `desc`, `date`, `imageurl`) VALUES ('$title', '$desc', '$date', '$target');") or die(mysql_error());
    }
}
include 'DBLibrary/closeDB.php';
?>
